将MediaRecorder(android的视频录制类)的输出的视频流编码为H264(但是H264格式的视频Android目前的版本只支持解码,不支持该格式的编码。为了采用H264编码方式传输数据需要使用Java的jni技术[5],通过使用C/C 编写H264编码函数。为了在Android中使用C/C 的代码,必须使用Android NDK对C/ C 源码进行编译[6]生成库文件供Android调用实现对数据进行H264格式的编码。),通过rtp协议发送给服务端,rtmp服务器将接收到的H264视频数据进行播放
private SessionBuilder() {}
//设置为私有函数,这样外界无法构造出一个SessionBuilder对象,只能通过getInstance对象。
//自定义检查点: 1 2 3
/**
* Returns a reference to the {@link SessionBuilder}.
* @return The reference to the {@link SessionBuilder}
*/
public final static SessionBuilder getInstance()
{
if (sInstance == null)
{
synchronized (SessionBuilder.class)
{
if (sInstance == null)
{
SessionBuilder.sInstance = new SessionBuilder();
}
}
}
return sInstance;
}
//获取一个真正的SessionBuilder对象
//自定义检查点: 1 2 3
public SessionBuilder setContext(Context context)
{
mContext = context;
return this;
}
public Context getContext()
{
return mContext;
}
//设置mContext对象和获取mContext对象
//自定义检查点: 1 2 3
public SessionBuilder setDestination(InetAddress destination)
{
mDestination = destination;
return this;
}
/** Returns the destination ip address set with {@link #setDestination(InetAddress)}. */
public InetAddress getDestination()
{
return mDestination;
}
//对于mDestination的setter和getter方法
~~~~~~~~~~
public SessionBuilder setOrigin(InetAddress origin)
{
mOrigin = origin;
return this;
}
/** Returns the origin ip address set with {@link #setOrigin(InetAddress)}. */
public InetAddress getOrigin()
{
return mOrigin;
}
//对于mOrigin的setter和getter方法
~~~~~~~~~~~
public SessionBuilder setVideoQuality(VideoQuality quality)
{
mVideoQuality = VideoQuality.merge(quality, mVideoQuality);
return this;
}
/** Returns the VideoQuality set with {@link #setVideoQuality(VideoQuality)}. */
public VideoQuality getVideoQuality()
{
return mVideoQuality;
}
//对于mVideoQuality的setter和getter方法
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/** Sets the audio quality. */
public SessionBuilder setAudioQuality(AudioQuality quality)
{
mAudioQuality = AudioQuality.merge(quality, mAudioQuality);
return this;
}
/** Returns the AudioQuality set with {@link #setAudioQuality(AudioQuality)}. */
public AudioQuality getAudioQuality()
{
return mAudioQuality;
}
//对于mAudioQuality的setter和getter方法
~~~~~~~~~~
public SessionBuilder setAudioEncoder(int encoder)
{
mAudioEncoder = encoder;
return this;
}
public int getAudioEncoder()
{
return mAudioEncoder;
}
//对于mAudioEncoder的setter和getter方法
~~~~~~~
public SessionBuilder setVideoEncoder(int encoder)
{
mVideoEncoder = encoder;
return this;
}
public int getVideoEncoder()
{
return mVideoEncoder;
}
//设置mVideoEncoder的setter和getter方法
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public SessionBuilder setCamera(int camera)
{
mCamera = camera;
return this;
}
public int getCamera()
{
return mCamera;
}
//对mCamera的setter和getter方法
~~~~~~~~~~~~~~~~~~~~~~~~~~
public SessionBuilder setFlashEnabled(boolean enabled)
{
mFlash = enabled;
return this;
}
public boolean getFlashState()
{
return mFlash;
}
//对mFlash的setter和getter方法
~~~~~~~~~~~~~~~~~~~~~~~~~~~
public SessionBuilder setTimeToLive(int ttl)
{
mTimeToLive = ttl;
return this;
}
public int getTimeToLive()
{
return mTimeToLive;
}
//对mTimeToLive的setter和getter方法
//自定义检查点:1 2 3
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public SessionBuilder setSurfaceHolder(SurfaceHolder surfaceHolder)
{
mSurfaceHolder = surfaceHolder;
return this;
}
public SurfaceHolder getSurfaceHolder()
{
return mSurfaceHolder;
}
//对mSurfaceHolder的setter和getter方法
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public SessionBuilder clone()
{
return new SessionBuilder()
.setDestination(mDestination)
.setOrigin(mOrigin)
.setSurfaceHolder(mSurfaceHolder)
.setVideoQuality(mVideoQuality)
.setVideoEncoder(mVideoEncoder)
.setFlashEnabled(mFlash)
.setCamera(mCamera)
.setTimeToLive(mTimeToLive)
.setAudioEncoder(mAudioEncoder)
.setAudioQuality(mAudioQuality)
.setContext(mContext);
}
//构造当前对象的一个复制品
~~~~~~~~~~~~~~~~~~~~~~~~~~
然后就剩下最后一个函数build:
由于这个函数涉及到别的类,所以等后面分析好了再回来看。
评论